<template>
	<view class="conter">


		<view class="header" style="color: #000000;" @tap="goBack(id)">
			<view class="arrow">
			</view>
			<view class="title">
				{{title}}
			</view>
		</view>
		
		


		<!-- <view class="padding-left padding-right padding-top margin-bottom">
			<u-search action-text="搜索" @change="searchList" :show-action="true" @clear="clearSearch"
				placeholder="搜索类名..." v-model="keyword" :animation="true">
			</u-search>
		</view> -->







		<!-- <view class="text-tab">
			<view class="box">
				<view class="marige-bor" v-for="(item, index) in textList" :key="index">
					<view class="diso-flex">
						<view class="">
							{{item.name}}
						</view>
						<view class="conter-image" @tap="skip(item)">
							<u-radio-group v-model="value">
								<u-radio active-color="#AFB3F1" :name="item.id" ></u-radio>
							</u-radio-group>
						</view>
					</view>
				</view>
			</view>
		</view> -->



		<block v-for="(item, index) in textListFrom" :key="index">
			<view class="flex align-center margin-top u-border-bottom wh96"
				style="padding: 20rpx; margin: 10rpx auto;
				background-color: #FFFFFF;
			"
				@tap="goBackAdd1(item)">
				<image class="w150 h150" :src="img + item.image" mode=""></image>
				<view class="padding-left" style="line-height: 60rpx;">
					<view>{{item.name}}</view>
					<view>数量：{{item.stock_num}}</view>
					<view>单位：{{item.unit_name}}</view>
				</view>
			</view>
		</block>



		<!-- <view class="add" @tap="goBackAdd('/pages/shopping/addShopping')">
			<image class="w100 h100" src="../../static/index/add.png" mode=""></image>
		</view> -->

		




		<!-- 底部弹层 -->
		<u-popup v-model="redactShow" mode="bottom" width="100%" height="426rpx" border-radius="40">
			<view class="padd-text" v-for="(item, index) in list" :key="index" @click="elect(item, index)">
				<text :class="[index == tabText ? 'color-text' : 'none-color']">{{item.name}}</text>
			</view>
		</u-popup>




		<u-popup v-model="popupShow" mode="center" width="70%" height="280rpx" border-radius="10">
			<view class="input-text">
				添加商品分类
			</view>
			<view class="input-val">
				<input type="text" v-model="name" style="background-color: #F0F0F0; text-align: center;height: 100%;"
					placeholder="请输入商品类目" />
			</view>
			<view class="text-select">
				<view class="" @click="popupShow = false">
					取消
				</view>
				<view class="" @click="addGoods">
					确定
				</view>
			</view>
		</u-popup>


		<u-popup v-model="popupShow1" mode="center" width="70%" height="280rpx" border-radius="10">
			<view class="input-text">
				修改-{{removeName}}
			</view>
			<view class="input-val">
				<input type="text" v-model="name" style="background-color: #F0F0F0; text-align: center;height: 100%;"
					placeholder="请输入修改名称" />
			</view>
			<view class="text-select">
				<view class="" @click="popupShow1 = false">
					取消
				</view>
				<view class="" @click="removeClass">
					确定
				</view>
			</view>
		</u-popup>

		<u-popup v-model="popupShow2" mode="center" width="70%" height="200rpx" border-radius="10">
			<view class="input-text">
				删除-{{removeName}}
			</view>
			<view class="text-select">
				<view class="" @click="popupShow2 = false">
					取消
				</view>
				<view class="" @click="deleteClass">
					确定
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import headerBox from '../../components/header/header.vue'

	export default {
		components: {
			headerBox
		},
		data() {
			return {
				title: '分类',
				textList: [],
				addUrl: '',
				redactShow: false,
				list: [{
						name: '编辑',
						show: true
					}, {
						name: '查看',
						show: true
					},
					// {
					// 	name: '删除',
					// 	show: true
					// },
					{
						name: '取消',
						show: false
					}
				],
				listFrom: [{
					name: '出库'
				}, {
					name: '入库'
				}],
				current: 0,
				tabText: 0,
				popupShow: false,
				popupShow1: false,
				popupShow2: false,
				popupShow3: false,
				value: '',
				name: '',
				removeName: '',
				id: '',
				num: '',
				loadStatus: 'loadmore',
				flowList: [],
				page: 1,
				pagesize: 10,
				textListFrom: [],
				textListFromType: [],
				keyword: '',
				storskId: '',
				img: this.$images,
				dataLenth: '',
			}
		},
		onLoad(e) {
			console.log('e',e)
			this.storskId = e.id
			this.title = e.name
			this.getStockListFrom(this.storskId)
		},
		onShow() {
			this.redactShow = false
			// if(this.dataLenth == '') {
			// 	console.log('444444')
			// 	this.$tools.msg('暂没数据！')
			// }
		},
		// onReachBottom() {
		// 	this.page++
		// 	this.getStockListFrom()
		// },
		methods: {
			goBackAdd(url) {
				uni.navigateTo({
					url,
				})
			},

			searchList() {
				this.textListFrom = []
				this.getStockListFrom()
			},

			goBackAdd1(item) {
				// uni.navigateTo({
				// 	url: '/pages/shopping/alterPhone?item=' + JSON.stringify(item)
				// })
				uni.setStorageSync('item', item)
				uni.navigateTo({
					url: '/pages/shopping/alterPhone'
				})
			},

			async getStorkList() {
				const res = await this.$u.post("api/jinxiao.Company/index");
			},


			addRandomData() {
				for (let i = 0; i < 10; i++) {
					let index = this.$u.random(0, this.list.length - 1);
					let item = JSON.parse(JSON.stringify(this.list[index]))
					item.id = this.$u.guid();
					this.flowList.push(item);
				}
			},

			change(index) {
				console.log('index', index)
				this.current = index;
				this.textList = []
				this.textListFrom = []
				// this.id = ''
				this.page = 1
				this.getStockListFrom()

			},

			async getStockListFrom(id) {
				const res = await this.$u.post("api/Invoic/store_info", {
					store_id: this.storskId,
					// page: this.page,
					// pagesize: this.pagesize,
					// search: this.keyword ? this.keyword : '',
					// classify_id: this.id ? this.id : '',

				});
				this.popupShow3 = false
				if(res.data == null) return this.$tools.msg('暂无数据！')
				this.textListFrom = [...this.textListFrom, ...res.data]   // 出库
				this.dataLenth = res.data
				console.log('11111', res.data)
				// this.textListFrom = res.data
			},

			clearSearch() {
				this.getStockListFrom()
			},

			async getGoodsListFrom1(id) {
				this.textListFrom = []
				const res = await this.$u.post("/api/jinxiao.Goods/goods_search", {
					page: this.page,
					pagesize: this.pagesize,
					search: this.keyword ? this.keyword : '',
				});
				this.popupShow3 = false
				this.textListFrom = [...this.textListFrom, ...res.data.$lists]
			},

			async getGoodsListFrom2(id) {
				this.textListFrom = []
				console.log('sosuo111', this.keyword, id == '', id)
				const res = await this.$u.post("/api/jinxiao.Goods/goods_search", {
					page: this.page,
					pagesize: this.pagesize,
					classify_id: id ? id : '',
				});
				this.popupShow3 = false
				this.textListFrom = [...this.textListFrom, ...res.data.$lists]
				this.textListFromType = res.data.type
			},


			// 添加商品
			async addGoods() {
				if (this.name == '') return this.$tools.msg('请输入商品类目')
				const res = await this.$u.post("api/jinxiao.Classify/add?name=" + this.name);
				if (res.code !== 1) return this.$tools.msg(res.msg)
				this.popupShow = false
				this.getGoodsList()
				this.$tools.msg(res.msg)
				console.log(res)
			},


			// 确定修改
			async removeClass() {
				const res = await this.$u.post("api/jinxiao.Classify/edit?name=" + this.name + "&id=" + this.id);
				if (res.code !== 1) return this.$tools.msg(res.msg)
				this.$tools.msg(res.msg)
				this.getGoodsList()
				this.popupShow1 = false
				this.redactShow = false
				this.name = ''
				console.log('确定修改', res)
			},





			goBack(id) {
				console.log(id)
				uni.navigateBack({
					delta: 1
				})
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				prevPage.$vm.classId = this.value; //修改上一页data里面的searchVal参数值为1211
				prevPage.$vm.className = this.className;

			},


			skip(item) {
				// this.redactShow = true
				// this.removeName = item.name

				this.current = 0
				this.id = item.id
				this.getStockListFrom(item.id)
				console.log('this.id ', this.id)

			},

			// 删除类目
			async deleteClass() {
				if (this.id == '') return this.$tools.msg('请选择类目')
				const res = await this.$u.post("api/jinxiao.Classify/delete?id=" + this.id);
				if (res.code !== 1) return this.$tools.msg(res.msg)
				this.$tools.msg(res.msg)
				this.getGoodsList()
				this.popupShow2 = false
				this.redactShow = false
				console.log('确定修改', res)
			},

			elect(item, index) {
				console.log(item)
				this.tabText = index
				this.redactShow = item.show
				if (index == 0) {
					console.log('000000', this.id)
					if (this.id == '') return this.$tools.msg('请选择')
					this.popupShow1 = true
					this.name = ''
				} else if (index == 1) {

					uni.navigateTo({
						url: '/pages/shopping/index?classId=' + this.id + '&name=' + this.removeName
					})
					// this.getGoodsList()
					// 调用删除事件
				} else if (index == 2) {
					this.popupShow2 = true
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	.conter {
		width: 100%;
		// height: 100vh;
		position: relative;
		// background-color: #FFFFFF;

		.demo-warter {
			border-radius: 8px;
			margin: 5px;
			background-color: #ffffff;
			padding: 8px;
			position: relative;
		}

		.u-close {
			position: absolute;
			top: 32rpx;
			right: 32rpx;
		}

		.demo-image {
			width: 100%;
			border-radius: 4px;
		}

		.demo-title {
			font-size: 30rpx;
			margin-top: 5px;
			color: $u-main-color;
		}

		.demo-tag {
			display: flex;
			margin-top: 5px;
		}

		.demo-tag-owner {
			background-color: $u-type-error;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			padding: 4rpx 14rpx;
			border-radius: 50rpx;
			font-size: 20rpx;
			line-height: 1;
		}

		.demo-tag-text {
			border: 1px solid $u-type-primary;
			color: $u-type-primary;
			margin-left: 10px;
			border-radius: 50rpx;
			line-height: 1;
			padding: 4rpx 14rpx;
			display: flex;
			align-items: center;
			border-radius: 50rpx;
			font-size: 20rpx;
		}

		.demo-price {
			font-size: 30rpx;
			color: $u-type-error;
			margin-top: 5px;
		}

		.demo-shop {
			font-size: 22rpx;
			color: $u-tips-color;
			margin-top: 5px;
			text-align: center;
		}





		.header {
			width: 100%;
			height: 150rpx;
			line-height: 150rpx;
			display: flex;
			align-items: center;
			// padding-left: 10rpx;
			padding-top: 30rpx;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			background: linear-gradient(to right, #656CE6, #9397FC);

			.arrow {
				position: relative;
				display: inline-block;
			}

			.arrow::before {
				content: '';
				width: 10px;
				height: 10px;
				border: 0px;
				border-bottom: solid 2px #fff;
				border-left: solid 2px #fff;
				-ms-transform: rotate(45deg);
				-webkit-transform: rotate(45deg);
				transform: rotate(45deg);
				position: absolute;
				top: 50%;
				left: 0;
				margin-top: -4px;
				margin-left: 28rpx;
			}

			.title {
				color: #fff;
				margin: 0 auto;
			}
		}


		.text-tab {
			width: 100%;
			// padding: 30rpx;
			padding-bottom: 0;


			.box {
				width: 98%;
				margin: 0 auto;
				background-color: #FFFFFF;
				border-radius: 10rpx;
			}

			.marige-bor {
				width: 90%;
				margin: 0 auto;
				color: #333333;
				display: flex;
				font-size: 28rpx;
				align-items: center;
				border-bottom: 1rpx solid #F0F0F0;
				justify-content: space-between;

				.diso-flex {
					width: 100%;
					height: 80rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
				}

				.conter-image {
					display: flex;
					align-items: center;
					width: 22rpx;
					height: 36rpx;
					font-weight: 700;
					color: #999;
				}
			}

			.marige-bor:last-child {
				border-bottom: 0;
			}
		}

		// 加号
		.add {
			position: fixed;
			bottom: 200rpx;
			right: 40rpx;
			width: 100rpx;
			height: 100rpx;
			text-align: center;
			line-height: 100rpx;
			border-radius: 50%;
			font-size: 100rpx;
			color: #FFFFFF;
		}

		.total {
			width: 100%;
			position: absolute;
			bottom: 0;
			left: 0;
			height: 100rpx;
			padding: 0 60rpx 0 30rpx;
			background-color: #FFFFFF;
		}

	}

	.padd-text {
		width: 80%;
		height: 106rpx;
		line-height: 106rpx;
		text-align: center;
		font-size: 28rpx;
		color: #333;
		border-bottom: 1rpx solid #EEEEEE;
		margin: 0 auto;
	}

	.color-text {
		color: #7278EC;
	}

	.none-color {
		color: #000;
	}

	.input-text {
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		margin-top: 10rpx;
	}

	.input-val {
		width: 80%;
		height: 60rpx;
		line-height: 60rpx;
		margin: 0 auto 30rpx;
	}

	.text-select {
		width: 90%;
		margin: 0 auto;
		border-top: 1rpx solid #F0F0F0;
		display: flex;
		color: #AFB3F1;
		// padding-top: 20rpx;
		justify-content: space-around;

		view {
			width: 50%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border-right: 1rpx solid #F0F0F0;
		}

		view:last-child {
			border-right: 0;
		}
	}
</style>
